﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AD.BLL;
using AD.Model;

public partial class Manager_User_PageData_InstallLogList : WebManagerForm
{
    public IList<InstallLogMod> Logs = new List<InstallLogMod>();
    public int currPageIndex = 1;
    public int MaxSize = 0;
    public int MaxPage = 0;
    public string startTime = "";
    public string endTime = "";
    public string installSource = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        string indexstr = Request.QueryString["pageIndex"];
        string action = Request.QueryString["action"];
        string idstrs = Request.Params["ids"];

        installSource = Request.Params["installSource"];
        startTime = Request.Params["startTime"];
        endTime = Request.Params["endTime"];
        string filter = " userName like '%%'";
        if (!string.IsNullOrEmpty(installSource))
        {
            if (!installSource.Equals("0"))
                filter = string.Format(" installSource like '%{0}'% ", installSource);
        }
        if (!string.IsNullOrEmpty(startTime))
            filter += string.Format(" and CommitDate>='{0}' ", startTime);
        if (!string.IsNullOrEmpty(endTime))
            filter += string.Format(" and CommitDate<='{0}'", endTime);

        if (!string.IsNullOrEmpty(action))
        {
            bool effect = int.TryParse(indexstr, out currPageIndex);
            if (action.Equals("queryFilter") && effect == true)
            {
                SetDataBind(filter, UtilHepler.PAGE_SIZE, 1);
            }
            else if (action.Equals("gopage") && effect == true)
            {
                SetDataBind(filter, UtilHepler.PAGE_SIZE, currPageIndex);
            }
            else if (action.Equals("delete") && effect == true)
            {
                InstallLogBLL.Delete(idstrs);
                SetDataBind(filter, UtilHepler.PAGE_SIZE, currPageIndex);
            }
            else if (action.Equals("deleteAll") && !string.IsNullOrEmpty(idstrs))
            {
                List<int> ids = GetIdToList(idstrs);
                foreach (var id in ids)
                {
                    InstallLogBLL.Delete(id);
                }
                SetDataBind(filter, UtilHepler.PAGE_SIZE, 1);
            }
        }
    }


    void SetDataBind(string filter, int pageSize, int index)
    {
        Logs = InstallLogBLL.QueryByPage(filter, pageSize, index == 0 ? 0 : index - 1, out MaxSize);
        MaxPage = MaxSize / UtilHepler.PAGE_SIZE;
        if (MaxSize % UtilHepler.PAGE_SIZE != 0)
            MaxPage += 1;
        if (Logs == null) Logs = new List<InstallLogMod>();
    }
}